package Person.File;

import java.io.File;

public class JavaDemo {
    public static void main(String[] args) {
        File file = new File("D:"+File.separator+"hello");
        renameDir(file);
    }
    public static void renameDir(File file){
        if(file.isDirectory()){
            File results[] = file.listFiles();
            if(results!=null){
                for(int i=0;i< results.length;i++){
                    renameDir(results[i]);
                }
            }
        }else{
            if(file.isFile()){
                String filename = null;
                if(file.getName().endsWith(".java")){
                    filename = file.getName().substring(0,file.getName().lastIndexOf("."))+".txt";
                    File newFile = new File(file.getParentFile(),filename);
                    file.renameTo(newFile);
                }
            }
        }
    }
}
